const db = require('./db/dbconfig.js');

async function checkUsers() {
  try {
    console.log('=== 检查用户数据 ===');
    
    const users = await db.query('SELECT user_id, username, password, LENGTH(password) as pwd_len FROM users');
    console.log('用户数据:', JSON.stringify(users, null, 2));
    
    console.log('\n=== 密码分析 ===');
    users.forEach(user => {
      console.log(`用户ID: ${user.user_id}, 用户名: ${user.username}`);
      console.log(`密码长度: ${user.pwd_len}`);
      console.log(`密码前10个字符: ${user.password.substring(0, 10)}`);
      console.log(`密码是否为bcrypt格式: ${user.password.startsWith('$2')}`);
      console.log('---');
    });
    
    console.log('\n=== 测试密码验证 ===');
    
    // 测试用户70的密码
    const user70 = users.find(u => u.username === '70');
    if (user70) {
      console.log('用户70密码验证:');
      console.log('密码:', user70.password);
      console.log('是否匹配"123456":', user70.password === '123456');
    }
    
    // 测试用户test的密码
    const userTest = users.find(u => u.username === 'test');
    if (userTest) {
      console.log('用户test密码验证:');
      console.log('密码:', userTest.password);
      console.log('是否为bcrypt格式:', userTest.password.startsWith('$2'));
    }
    
  } catch (error) {
    console.error('错误:', error);
  }
}

checkUsers();